// RotateMe.cpp : Defines the entry point for the application.
//

#include <windows.h>

static DWORD GetScreenOrientation()
{
	DEVMODE deviceMode;
    
	memset(&deviceMode, 0, sizeof(deviceMode));
	deviceMode.dmSize = sizeof(deviceMode);
	deviceMode.dmFields = DM_DISPLAYORIENTATION;

	if (ChangeDisplaySettingsEx(NULL,  &deviceMode,  NULL,  CDS_TEST, NULL) == DISP_CHANGE_SUCCESSFUL)
		return deviceMode.dmDisplayOrientation;
	else
		return DMDO_DEFAULT;
}

static void SetScreenOrientation(DWORD dwOrientation)
{
	DEVMODE deviceMode;
    
	memset(&deviceMode, 0, sizeof(deviceMode));
	deviceMode.dmSize = sizeof(deviceMode);
	deviceMode.dmFields = DM_DISPLAYORIENTATION;
	deviceMode.dmDisplayOrientation = dwOrientation;

	ChangeDisplaySettingsEx(NULL, &deviceMode, NULL, CDS_RESET, NULL);
}


int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPTSTR    lpCmdLine,
                   int       nCmdShow)
{
	if (GetScreenOrientation() == DMDO_0)
		SetScreenOrientation(DMDO_90);
	else
		SetScreenOrientation(DMDO_0);
}